import axios from 'axios'
import { getToken } from '@/auth/auth.service'
axios.defaults.baseURL="https://localhost:44325/api/"
axios.defaults.headers['X-Requested-With']="XMLHttpRequest"//异步
axios.defaults.headers.post['Content-Type']='application/json'
import {ElMessage} from 'element-plus'
//拦截器
//请求拦截器
axios.interceptors.request.use(options=>{
	//为请求添加token
	const jwtToken = getToken()
	if(jwtToken)
	{
		options.headers.Authorization = `Bearer ${jwtToken}`
	}
	return options

})
//响应拦截器
axios.interceptors.response.use(res=>{
	//响应成功的情况下
	console.log(res,"正确")
	return res
},error=>{
	//错误
	ElMessage({
		message:error.response.data.message,
		type:"error"
	})
	console.log(error.response.data.message,"错误")
	return error
})
export default axios
